package cn.doitedu.utils;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author 涛哥
 * @nick_name "deep as the sea"
 * @contact qq:657270652 wx:doit_edu
 * @site www.doitedu.cn
 * @date 2021-03-30
 * @desc 各类外部链接创建工具类
 */
@Slf4j
public class ConnectionUtils {
    static Config config = ConfigFactory.load();
    public static Connection getClickhouseConnection() throws Exception {

        Class.forName(config.getString(ConfigNames.CK_JDBC_DRIVER));
        Connection conn = DriverManager.getConnection(config.getString(ConfigNames.CK_JDBC_URL));
        log.debug("clickhouse jdbc 连接创建成功");
        return conn;
    }

    public static org.apache.hadoop.hbase.client.Connection getHbaseConnection() throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", config.getString(ConfigNames.HBASE_ZK_QUORUM));
        org.apache.hadoop.hbase.client.Connection conn = ConnectionFactory.createConnection(conf);
        log.debug("hbase 连接创建成功");
        return conn;
    }

}
